﻿using System;
using System.ComponentModel;
using System.Windows;

namespace ImageProcessor.Shared
{
    public class ImageProcessorBaseVM : DependencyObject, INotifyPropertyChanged
    {
        public ImageProcessorBaseVM(MainViewModel mainVM)
        {
            ExecuteCommand = new RelayCommand(ExecuteCore, CanExecute);

            MainVM = mainVM;
        }

        private void ExecuteCore(object obj)
        {
            try
            {
                Execute(obj);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Что-то пошло не так...");
            }
        }

        public MainViewModel MainVM { get; private set; }

        public RelayCommand ExecuteCommand { get; private set; }

        protected virtual void Execute(object obj)
        {
            
        }

        protected virtual bool CanExecute(object obj)
        {
            return true;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}